class Solution {
public:
    vector<int> singleNumber(vector<int>& nums) {
        std::sort(nums.begin(), nums.end());
        size_t pre = 0;
        size_t suf = 1;
        size_t fro = nums.size() - 1;
        size_t lat = fro - 1;
        vector<int> v;
        while ((nums[pre] == nums[suf] || nums[lat] == nums[fro]) && (suf != fro && lat != pre))
        {
            if (nums[pre] == nums[suf])
            {
                pre += 2;
                suf = pre + 1;
            }
            if (nums[lat] == nums[fro])
            {
                fro -= 2;
                lat = fro - 1;
            }
        }
        v.push_back(nums[pre]);
        v.push_back(nums[fro]);
        return v;
    }
};